package com.huawei.updatesdk.a.b.d.a;

import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.updatesdk.a.a.c.d;
import com.huawei.updatesdk.a.a.c.e;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import o.cfv;

public class c {
    public static final String CLIENT_API = "clientApi";
    private static final String END_FLAG = "_";
    private static String url;
    private String method_;
    private String ver_ = cfv.VER_NUMBER;

    private String a(Field field) throws IllegalAccessException, IllegalArgumentException {
        Object obj = field.get(this);
        return (obj == null || !(obj instanceof b)) ? obj != null ? String.valueOf(obj) : null : ((b) obj).toJson();
    }

    public static void a(String str) {
        url = str;
    }

    public String a() {
        return this.method_;
    }

    public String b() throws IllegalAccessException, IllegalArgumentException, ArrayIndexOutOfBoundsException {
        int i;
        c();
        Map e = e();
        String[] strArr = new String[e.size()];
        e.keySet().toArray(strArr);
        Arrays.sort(strArr);
        StringBuilder stringBuilder = new StringBuilder();
        int i2 = 0;
        while (true) {
            String a = a((Field) e.get(strArr[i2]));
            if (a != null) {
                stringBuilder.append(strArr[i2]).append(ContainerUtils.KEY_VALUE_DELIMITER).append(e.a(a)).append(ContainerUtils.FIELD_DELIMITER);
            }
            i = i2 + 1;
            if (i >= strArr.length) {
                break;
            }
            i2 = i;
        }
        i = stringBuilder.length();
        if (i > 0 && stringBuilder.charAt(i - 1) == '&') {
            stringBuilder.deleteCharAt(i - 1);
        }
        return stringBuilder.toString();
    }

    public void b(String str) {
        this.method_ = str;
    }

    protected void c() {
    }

    public void c(String str) {
        this.ver_ = str;
    }

    public String d() {
        return url + "clientApi";
    }

    protected Map<String, Field> e() {
        Map<String, Field> hashMap = new HashMap();
        for (Field field : d.a(getClass())) {
            field.setAccessible(true);
            String name = field.getName();
            if (name.endsWith("_")) {
                hashMap.put(name.substring(0, name.length() - "_".length()), field);
            }
        }
        return hashMap;
    }
}
